package com.example.test_app


import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.app.PendingIntent.getService
import android.content.Context
import android.hardware.input.InputManager
import android.os.Bundle
import android.view.View
import android.view.animation.BounceInterpolator
import androidx.appcompat.app.AppCompatActivity
import com.example.eventbus.EventBus
import com.example.eventbus.Subscribe
import com.example.test_app.bean.EventMsg
import com.example.test_app.view.SimpleWebpView
import com.facebook.drawee.backends.pipeline.Fresco

class MainActivity2 : AppCompatActivity() {
    private val fragment1 = VpFragment()
    private val fragment2 = VpFragment()

    private var sdv: SimpleWebpView? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EventBus.get().register(this)
        Fresco.initialize(this)
        setContentView(R.layout.activity_main2)


        supportFragmentManager.beginTransaction()
            .add(R.id.fg, fragment1)
            .add(R.id.fg,fragment2)
            .hide(fragment2)
            .commit()




        val path = "$filesDir/app-debug.apk"
        val cache = "$cacheDir"
//
//        var classLoader = ClassLoaderUtil.create(this@MainActivity2, path, cache, null)
//        clazz = classLoader.loadClass("com.example.test_code.MainActivity")
//        Toast.makeText(this@MainActivity2, "${clazz.toString()}", Toast.LENGTH_SHORT).show()


        sdv = findViewById(R.id.sdv)
    }

    var clazz: Class<*>? = null
    private var isLoad = false


    @Subscribe(sticky = true)
    fun aa(i: EventMsg) {
        isLoad = i.isaBoolean()
    }




    override fun onResume() {
        super.onResume()

    }


    fun show1(view: View) {
        supportFragmentManager.beginTransaction()
            .show(fragment1)
            .hide(fragment2)
            .commit()

        val inTranslation = ObjectAnimator()
        inTranslation.setPropertyName("translationX")
        inTranslation.setFloatValues(-200f, 0f)
        inTranslation.interpolator = BounceInterpolator()

        val inAlpha = ObjectAnimator()
        inAlpha.setPropertyName("alpha")
        inAlpha.setFloatValues(0f, 1f)

        var initInAnimatorSet = AnimatorSet()
        initInAnimatorSet.playTogether(inTranslation, inAlpha)
        initInAnimatorSet.setDuration(1000)
        initInAnimatorSet.setTarget(sdv)
        inTranslation.start()


    }

    fun show2(view: View) {
        sdv?.loadRes(R.drawable.botmenu_btn_live_a)
        sdv?.setAutoPlay(true)
        supportFragmentManager.beginTransaction()
            .show(fragment2)
            .hide(fragment1)
            .commit()

    }


}






